package cn.edu.lingnan.servlet;

import cn.edu.lingnan.service.ICompetitionService;
import cn.edu.lingnan.service.IParticipationService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/admin/delPart")
public class DelParticipation extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1
        String pid = req.getParameter("pid");
        String flag = req.getParameter("flag");
        System.out.println("[Debug 072] the flag is value is " + flag);
        System.out.println("[Debug 073] the pid is value is " + pid);
        //2
        IParticipationService service = new IParticipationService();
        if(flag!=null){//删除多个记录
            String[] allPid = pid.split(",");
            for (String onePid:allPid
            ) {
                service.delParticipation(Integer.parseInt(onePid));
            }
        }else {//否则删除单个记录
            service.delParticipation(Integer.parseInt(pid));
        }
        //3
        resp.sendRedirect("/queryAllPart");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
